package com.music.controller;

import com.music.pojo.Collect;
import com.music.service.CollectService;

import com.laoxuai.beans.annotation.Autowired;
import com.laoxuai.beans.annotation.Controller;
import com.laoxuai.ibatis.util.PageInfo;
import com.laoxuai.web.mvc.annotation.RequestMapping;
import com.laoxuai.web.mvc.annotation.ResponseBody;
import com.music.pojo.Collect;
import com.music.service.CollectService;
import com.music.util.Result;

import java.util.List;

@Controller
@RequestMapping("/collect")
public class CollectController {

    @Autowired
    private CollectService collectServiceImpl;

    /***
     * 新增
     * @param collect
     * @return
     */
    @RequestMapping("/insert")
    @ResponseBody
    public Result insert(Integer userId,Integer musicId) {
        int result = collectServiceImpl.insert(userId,musicId);
        return Result.success("添加成功", result);
    }

    /***
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Result delete(Integer id) {
        int result = collectServiceImpl.delete(id);
        return Result.success("删除成功", result);
    }

    /***
     * 修改
     * @param collect
     * @param id
     * @return
     */
    @RequestMapping(value="/update")
    @ResponseBody
    public Result update(Integer id, Collect collect) {
        collect.setId(id);
        int result = collectServiceImpl.update(collect);
        return Result.success("修改成功");
    }

    /***
     * 主键查询
     * @param id
     * @return
     */
    @RequestMapping("/get")
    @ResponseBody
    public Result getByPrimaryKey(Integer id) {
        Collect collect = collectServiceImpl.getByPrimaryKey(id);
        return Result.success("查询成功", collect);
    }

    @RequestMapping(value = "/page")
    @ResponseBody
    public Result page(Collect collect, int page, int size) {
        PageInfo<Collect> pageInfo = collectServiceImpl.listPageInfo(collect, page, size);
        return Result.success("查询成功", pageInfo);
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public Result list(Collect collect, int page, int size) {
        List<Collect> list = collectServiceImpl.listPage(collect, page, size);
        return Result.success("查询成功", list);
    }
}